package development;

import java.util.Hashtable;


import state.GameForm;
import state.GameGlobal;
import state.Image;
import state.Key;
import state.Sprite;
import state.TouchScreenListener;
import state.util.ImageUtil;

public class FrmTestTouchScreen extends GameForm {
  private Image buttonImage;
  private Image lightButtonImage;
  
  private Sprite buttonSprite;
  
  private static GameForm singleton;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmTestTouchScreen();
    }
    return singleton;
  }
  
  public void init(Hashtable parameters) {
    buttonImage = ImageUtil.getImage("button_nho.png");
    lightButtonImage = ImageUtil.makeBrighter(buttonImage, 4);
    
    buttonSprite = new Sprite(buttonImage, manager, 50, 50);
    buttonSprite.setTouchScreenListener(new TouchScreenListener() {
      public void pointerReleased(Sprite source, int x, int y) {
        if (source.getImage() == buttonImage) {
          source.setImage(lightButtonImage);
        } else {
          source.setImage(buttonImage);
        }
      }
      
      public void pointerPressed(Sprite source, int x, int y) {
      }
      
      public void pointerDragged(Sprite source, int x, int y) {
        source.setPosition(x - source.getWidth() / 2, y - source.getHeight() / 2);
      }
    });
  }
  
  public void keyReleased(int keyCode) {
    if (keyCode == Key.SOFT_RIGHT) {
      GameGlobal.nextState(FrmMenu.instance(), null);
    }
  }

  protected void destroy() {
    buttonImage = null;
    lightButtonImage = null;
    
    buttonSprite = null;
  }
}
